package com.kf.smartpark.splash

import androidx.lifecycle.viewModelScope
import com.kf.common.entity.BaseEntity
import com.kf.common.mvi.viewmodel.BaseViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class SplashViewModel : BaseViewModel<SplashModel, SplashState>() {
    override fun createState(): SplashState {
        return SplashState(BaseEntity(200, "", SplashEntity("3")))
    }

    override fun createModel(): SplashModel {
        return SplashModel()
    }

    fun splashTime() {
        mutableContainer.updateRequestState {
            copy(
                request = true
            )
        }
        mutableContainer.updateRequestState {
            copy(
                complate = true
            )
        }
        viewModelScope.launch(Dispatchers.IO) {
            for (i in 3 downTo 0) {
                mutableContainer.updateUiState {
                    copy(BaseEntity(200, "", SplashEntity("${i}s")))
                }
                delay(1000)
            }
        }
    }

}